<template>
  <PackageList
      :table="table"
      :pagination="pagination"
      :loading="loading"
      @wmsHandle="(row) => emit('wmsHandle', row)"
  />
</template>

<script setup name="OrderList">
import { PackageList } from '@/components'
import columnsMap from '@/components/PackageList/columns'
import {useList, useListFn} from '@/hooks'
import {getInOrderListApi} from '@/service/enterStore'
import {onMounted} from 'vue'

const props = defineProps({
  wmsStatus: Number
})
const emit = defineEmits(['wmsHandle'])

// 创建表格合并的列配置函数
const {flatTable, tableSpanMerge} = useListFn({
  mergeRowsProps: ['trackingNo', 'logisticsCompany']
})
// list组件数据
const [loading, table, pagination] = useList({
  columns: columnsMap.get(props.wmsStatus),
  load: onLoad,
  tableAttrs: {
    spanMethod: tableSpanMerge
  }
})

// 获取表格数据
async function onLoad ({trackingNo = '', orderNo = ''} = {}) {
  loading.value = true
  const res = await getInOrderListApi({
    pageNo: pagination.currentPage,
    pageSize: pagination.pageSize,
    wmsStatus: props.wmsStatus,
    trackingNo,
    orderNo
  })
  if (res.code === __code) {
    table.rows = flatTable(res.data?.list || [])
    pagination.total = res.data?.total || 0
  }
  loading.value = false
}

// 初始化加载
function resetLoad () {
  pagination.currentPage = 1
  onLoad()
}

onMounted(() => {
  onLoad()
})

defineExpose({
  onLoad,
  resetLoad
})
</script>

<style lang="less" src="./index.less" module="styles"></style>

